home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / create5a / form1.frm next >
Text File  |  1999-10-08  |  6KB  |  154 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   4875
  6.    ClientLeft      =   1785
  7.    ClientTop       =   1455
  8.    ClientWidth     =   5415
  9.    LinkTopic       =   "Form10"
  10.    ScaleHeight     =   4875
  11.    ScaleWidth      =   5415
  12.    Begin VB.TextBox Text1 
  13.       Height          =   285
  14.       Left            =   480
  15.       TabIndex        =   3
  16.       Top             =   120
  17.       Width           =   3735
  18.    End
  19.    Begin VB.CommandButton Command1 
  20.       Caption         =   "Load"
  21.       Height          =   375
  22.       Left            =   4320
  23.       TabIndex        =   2
  24.       Top             =   60
  25.       Width           =   855
  26.    End
  27.    Begin MSComctlLib.TreeView TreeView1 
  28.       Height          =   1935
  29.       Left            =   0
  30.       TabIndex        =   0
  31.       Top             =   480
  32.       Width           =   3015
  33.       _ExtentX        =   5318
  34.       _ExtentY        =   3413
  35.       _Version        =   393217
  36.       Style           =   7
  37.       Appearance      =   1
  38.    End
  39.    Begin VB.Label Label1 
  40.       Caption         =   "File"
  41.       Height          =   255
  42.       Left            =   120
  43.       TabIndex        =   1
  44.       Top             =   120
  45.       Width           =   495
  46.    End
  47. End
  48. Attribute VB_Name = "Form1"
  49. Attribute VB_GlobalNameSpace = False
  50. Attribute VB_Creatable = False
  51. Attribute VB_PredeclaredId = True
  52. Attribute VB_Exposed = False
  53. Option Explicit
  54. ' Load a TreeView control from a file that uses tabs
  55. ' to show indentation.
  56. Private Sub LoadTreeViewFromFile(ByVal file_name As String, ByVal trv As TreeView)
  57. Dim fnum As Integer
  58. Dim text_line As String
  59. Dim level As Integer
  60. Dim tree_nodes() As Node
  61. Dim num_nodes As Integer
  62.  
  63.     fnum = FreeFile
  64.     Open file_name For Input As fnum
  65.  
  66.     TreeView1.Nodes.Clear
  67.     Do While Not EOF(fnum)
  68.         ' Get a line.
  69.         Line Input #fnum, text_line
  70.  
  71.         ' Find the level of indentation.
  72.         level = 1
  73.         Do While Left$(text_line, 1) = vbTab
  74.             level = level + 1
  75.             text_line = Mid$(text_line, 2)
  76.         Loop
  77.  
  78.         ' Make room for the new node.
  79.         If level > num_nodes Then
  80.             num_nodes = level
  81.             ReDim Preserve tree_nodes(1 To num_nodes)
  82.         End If
  83.  
  84.         ' Add the new node.
  85.         If level = 1 Then
  86.             Set tree_nodes(level) = TreeView1.Nodes.Add(, , , text_line)
  87.         Else
  88.             Set tree_nodes(level) = TreeView1.Nodes.Add(tree_nodes(level - 1), tvwChild, , text_line)
  89.             tree_nodes(level).EnsureVisible
  90.         End If
  91.     Loop
  92.  
  93.     Close fnum
  94. '''
  95. '''Dim i As Integer
  96. '''Dim factory As Node
  97. '''Dim group As Node
  98. '''Dim person As Node
  99. '''
  100. '''    ' Load pictures into the ImageList.
  101. '''    For i = 1 To 6
  102. '''        TreeImages.ListImages.Add , , TreeImage(i).Picture
  103. '''    Next i
  104. '''
  105. '''    ' Attach the TreeView to the ImageList.
  106. '''    OrgTree.ImageList = TreeImages
  107. '''
  108. '''    ' Create some nodes.
  109. '''    Set factory = OrgTree.Nodes.Add(, , "f R & D", "R & D", otFactory, otFactory2)
  110. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Engineering", "Engineering", otGroup, otGroup2)
  111. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Cameron, Charlie", "Cameron, Charlie", otPerson, otPerson2)
  112. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Davos, Debbie", "Davos, Debbie", otPerson, otPerson2)
  113. '''    person.EnsureVisible
  114. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Test", "Test", otGroup, otGroup2)
  115. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Able, Andy", "Andy, Able", otPerson, otPerson2)
  116. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Baker, Betty", "Baker, Betty", otPerson, otPerson2)
  117. '''    person.EnsureVisible
  118. '''
  119. '''    Set factory = OrgTree.Nodes.Add(, , "f Sales & Support", "Sales & Support", otFactory, otFactory2)
  120. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Showroom Sales", "Showroom Sales", otGroup, otGroup2)
  121. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Gaines, Gina", "Gaines, Gina", otPerson, otPerson2)
  122. '''    person.EnsureVisible
  123. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Field Service", "Field Service", otGroup, otGroup2)
  124. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Helms, Harry", "Helms, Harry", otPerson, otPerson2)
  125. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Ives, Irma", "Ives, Irma", otPerson, otPerson2)
  126. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Jackson, Josh", "Jackson, Josh", otPerson, otPerson2)
  127. '''    person.EnsureVisible
  128. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Customer Support", "Customer Support", otGroup, otGroup2)
  129. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Klug, Karl", "Klug, Karl", otPerson, otPerson2)
  130. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Landau, Linda", "Landau, Linda", otPerson, otPerson2)
  131. '''    person.EnsureVisible
  132. '''
  133. End Sub
  134.  
  135. Private Sub Command1_Click()
  136.     LoadTreeViewFromFile Text1.Text, TreeView1
  137. End Sub
  138.  
  139. Private Sub Form_Load()
  140. Dim file_name As String
  141.  
  142.     file_name = App.Path
  143.     If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
  144.     file_name = file_name & "test.txt"
  145.     Text1.Text = file_name
  146. End Sub
  147. Private Sub Form_Resize()
  148. Dim hgt As Single
  149.  
  150.     hgt = ScaleHeight - TreeView1.Top
  151.     If hgt < 120 Then hgt = 120
  152.     TreeView1.Move 0, TreeView1.Top, ScaleWidth, hgt
  153. End Sub
  154.